const connection = require("../app/database")

class EnterService {
    async create(name,number,volume,categoryId,stashId,remark) {
        const statement = `INSERT INTO enter_record (name,number,volume,category_id,stash_id,remark) VALUES (?,?,?,?,?,?);`
        const [result] = await connection.execute(statement,[name,number,volume,categoryId,stashId,remark])
        return result
    }
    async getListCount() {
        const statement = `SELECT COUNT(*) AS totalCount from enter_record;`
        const [result] = await connection.execute(statement)
        return result[0]
    }
    async getList(pageSize,offset) {     
        const statement = `select * from enter_record order by id desc limit ${pageSize} offset ${offset};`;
        const [result] = await connection.execute(statement);
        return result
    }
    async remove(id) {
        const statement = `DELETE FROM enter_record WHERE id = ?;`
        const result = await connection.execute(statement,[id])
        return result
    }
}

module.exports = new EnterService()